package entity;

/**
 * @author 孙亚梅
 * @version V1.0
 * @Project javase2203
 * @Package entity
 * @Description:
 * @Date 2022/5/27 13:01
 */
public class Page {
    //页码，当前页数
    private  Integer pageIndex;

    //页大小，显示多少行数据
    private  Integer pageSize;

    //数据的总行数
    private  Integer totalCounts;

    //总页数
    private  Integer totalPages;

    //起始行
    private Integer startRows;

    public  Page(Integer pageIndex){
        this.pageIndex=pageIndex;
        //初始化每页显示条数，默认每页显示5条数据
        this.pageSize =5;
    }
    public  Page(Integer pageIndex ,Integer pageSize){
        this.pageIndex = pageIndex;
        this.pageSize =pageSize;
        //初始化每页显示条数，默认每页显示5条数据
        this.pageSize =5;
        //计算从第几条开始查询
        this.setStartRows((pageIndex-1)*pageSize);
    }



    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCounts() {
        return totalCounts;
    }

    public void setTotalCounts(Integer totalCounts) {
        this.totalCounts = totalCounts;
        //在设置总条数的时候，顺便计算总页数
        this.setTotalPages(totalCounts % pageSize==0 ? totalCounts / pageSize:totalCounts/pageSize+1);

    }

    public Integer getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }

    public Integer getStartRows() {
        return startRows;
    }

    public void setStartRows(Integer startRows) {
        this.startRows = startRows;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                ", totalCounts=" + totalCounts +
                ", totalPages=" + totalPages +
                ", startRows=" + startRows +
                '}';
    }
}
